#include<iostream>
using namespace std;
int main(){
    int m;
    cin>>m;
    string earlest,lastest;
    string ear="999",last="000";
    for (int i = 0; i < m; i++)
    {
        string s1,s2,s3;
        cin>>s1>>s2>>s3;
        if(s3>last){
            lastest=s1;
            last=s3;
        }
        if(s2<ear){
            earlest=s1;
            ear=s2;
        }
    }
    cout<<earlest<<" "<<lastest;
    

}